package com.baizhi.service.impl;

import com.baizhi.dao.EmpDao;
import com.baizhi.entity.Emp;
import com.baizhi.esdao.EmpEsDao;
import com.baizhi.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpDao ed;
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void insert(Emp emp) {
        //es插入
        System.out.println(emp);
        eed.insert(emp);
        //mysql插入
        ed.insert(emp);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void delete(int id) {
        eed.delete(id);
        ed.delete(id);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void update(Emp emp) {
        ed.update(emp);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Emp> selectAll() {
        return ed.selectAll();
    }

    @Override
    @Transactional(readOnly = true)
    public Emp selectOne(int id) {
        return ed.selectOne(id);
    }
    @Resource
    private EmpEsDao eed;
    @Override
    @Transactional(readOnly = true)
    public List<Emp> selectByCon(String con) {
        return eed.selectByCon(con);
    }
}
